package bzqn.com.rongcloudsdk.utils;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.net.Uri;

import bzqn.com.rongcloudsdk.R;
import io.rong.imlib.model.Message;

/**
 * Created by a on 2017/5/15.
 */

public class NotifcationUtils {

    public static void showNotifcation(String title, String content, Context context, Message message){
        Notification.Builder builder = new Notification.Builder(context);
        Uri uri = Uri.parse("rong://" + context.getApplicationInfo().processName).buildUpon().appendPath("conversation").appendPath(message.getConversationType().getName().toLowerCase()).appendQueryParameter("targetId", message.getContent().getUserInfo().getUserId()).appendQueryParameter("title", title).build();
        Intent mIntent = new Intent(Intent.ACTION_VIEW, uri);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, mIntent, 0);
        builder.setContentIntent(pendingIntent);
        builder.setSmallIcon(R.mipmap.ic_launcher);
        builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),     R.mipmap.ic_launcher));
        builder.setAutoCancel(true);
        builder.setContentTitle(title);
        builder.setContentText(content);
        builder.setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE);
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, builder.build());
    }
}
